package umbral;

import org.bouncycastle.jce.interfaces.ECPrivateKey;
import org.bouncycastle.jce.interfaces.ECPublicKey;
import umbral.Helpers;

import javax.swing.text.Element;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.spec.InvalidKeySpecException;
import java.util.AbstractMap;

public class testUmbral {

    public static void main(String[] args) throws GeneralSecurityException, IOException {

        ECPrivateKey alicePrivate = Helpers.getRandomPrivateKey();
        ECPublicKey alicePublic = Helpers.getPublicKey(alicePrivate);
        System.out.println("alicePrivate:"+alicePrivate);
        System.out.println("alicePublic:"+alicePublic);

        ECPrivateKey aliceSigning = Helpers.getRandomPrivateKey();
        ECPublicKey aliceVerifying = Helpers.getPublicKey(aliceSigning);
        System.out.println("aliceSigning:"+aliceSigning);
        System.out.println("aliceVerifying:"+aliceVerifying);

        ECPrivateKey bobPrivate = Helpers.getRandomPrivateKey();
        ECPublicKey bobPublic = Helpers.getPublicKey(bobPrivate);

        ECPrivateKey bob2Private = Helpers.getRandomPrivateKey();
        ECPublicKey bob2Public = Helpers.getPublicKey(bobPrivate);

        byte[] plaintext = "Hello World!".getBytes();

        System.out.println("plaintext:"+plaintext);
        AbstractMap.SimpleEntry<byte[], Capsule> encrypt = pre.encrypt(alicePublic, plaintext);
        System.out.println("encrypt"+encrypt);

        byte[] ciphertext = encrypt.getKey();
        System.out.println("ciphertext:"+ciphertext);
        Capsule capsule = encrypt.getValue();
        System.out.println("capsule:"+capsule);
        byte[] result =  pre.decrypt(ciphertext, capsule, alicePrivate, true);
        System.out.println("hash_result:"+Helpers.bytesToHex(result));
        Helpers.bytesToHex(plaintext);
        System.out.println("hash_plain:"+Helpers.bytesToHex(plaintext));
      
    }

}
